<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的竞拍</title>
    <script src="/common/js/jquery.min.js" type="text/javascript"></script>
    <script src="/common/layui/layui.js" type="text/javascript"></script>
    <script src="/common/layui/layui.all.js" type="text/javascript"></script>
    <script src="/common/js/userServer.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/common/layui/css/layui.css">
</head>
<body>
<hr>
<div class="layui-row">
    <div class="layui-col-md3">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称：</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" id="sname" name="sname" lay-verity="required" autocomplete="off"
                />
            </div>
        </div>
    </div>
    <div class="layui-col-md2">
        <div class="layui-form-item">
            <label class="layui-form-label">商品类型：</label>
            <div class="layui-input-block">
                <select class="layui-input" type="text" id="stype" name="stype"
                        lay-verity="required" autocomplete="off">
                </select>
            </div>
        </div>
    </div>
    <div class="layui-col-md2">
        <div class="layui-form-item">
            <label class="layui-form-label">竞拍状态：</label>
            <div class="layui-input-block">
                <select class="layui-input" id="astatecode" name="astatecode"
                        lay-verity="required" autocomplete="off">
                    <option value="">请选择</option>
                    <option value="0">竞拍失败</option>
                    <option value="1">竞拍中</option>
                    <option value="2">竞拍成功</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-col-md2">
        <div class="layui-form-item">
            <label class="layui-form-label">商品状态：</label>
            <div class="layui-input-block">
                <select class="layui-input" id="aucstate" name="aucstate" lay-verity="required" autocomplete="off">
                    <option value="">请选择</option>
                    <option value="1">竞拍中</option>
                    <option value="2">已结束</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-col-md1">
        <div class="layui-form-item">
            <!--<label class="layui-form-label">商品状态：</label>-->
            <!--<div class="layui-input-block">-->
            <input type="button" class="layui-input" value="查询" onclick="queryData()"
                   style="width: 100px;margin-left: 30px; background-color: #f7514d"></input>
            <!--</div>-->
        </div>
    </div>
</div>
<hr>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!--<button class="layui-btn layui-btn-sm" onclick="queryData()" >查询</button>-->
        <!--                <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">新增用户</button>-->
        <!--        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="view">查看</a>
    {{# if(d.sstate == "竞拍中" && d.astate == "竞拍失败"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="auction">继续竞拍</a>
    {{#  } }}
    {{# if(d.applystate == "待支付"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="apply">支付</a>
    {{#  } }}
</script>
<script src="/common/js/jquery-2.1.4.js" charset="utf-8"></script>
<script src="/common/layui/layui.js" charset="utf-8"></script>
<script src="/common/js/userServer.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->


<script>
    $(function () {
        getGoodsType();
    });
    var static_index = "";
    var col = [
        {type: 'checkbox', fixed: 'left'}
        , {field: 'sid', title: '商品编号', sort: true}
        , {field: 'sname', title: '商品名称'}
        , {field: 'cou', title: '商品数量'}
        , {field: 'price', title: '起拍价'}
        , {field: 'preprice', title: '当前价格'}
        , {field: 'start', title: '开始时间'}
        , {field: 'end', title: '结束时间'}
        , {field: 'astate', title: '我的竞拍状态'}
        , {field: 'sstate', title: '商品状态'}
        , {field: 'applystate', title: '支付状态'}
        , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
    ];
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#test'
            , url: '/goods/myAuctionAdmin.do'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , page: true
            , id: 'testTable'
            , height: 615
            , request: {
                pageName: 'curr' //页码的参数名称，默认：page
                , limitName: 'nums' //每页数据量的参数名，默认：limit
            }
            , defaultToolbar: ['filter']
            , title: '类型数据表'
            , cols: [
                col
            ]
        });
        // $('table.layui-table thead tr th:eq(0)').addClass('layui-hide');
        // $('table:eq(1).layui-table thead tr th:eq(0)').addClass('layui-hide');
        // $('table:eq(6).layui-table thead tr th:eq(1)').addClass('layui-hide');

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            console.log(data)
            if (obj.event === 'view') {
                //打开查看窗口
                var sid = data.sid;
                layer.open({
                    type: 2,
                    area: ['1000px', '700px'],
                    skin: 'layui-layer-rim', //加上边框
                    // btn: ['关闭','false'],
                    shadeClose: true,
                    content: ["/goods/openGoodsDetailView.do?sid=" + sid, 'no'],
                    success: function (layero, index) {
                        static_index = index;
                        var iframe = window['layui-layer-iframe' + index];
                        iframe.child("view");
                    }
                });
            } else if (obj.event === 'auction') {
                //打开查看窗口
                var sid = data.sid;
                layer.open({
                    type: 2,
                    area: ['1000px', '700px'],
                    skin: 'layui-layer-rim', //加上边框
                    // btn: ['关闭','false'],
                    shadeClose: true,
                    content: ["/goods/openDetail.do?sid=" + sid, 'no'],
                    success: function (layero, index) {
                        // static_index = index;
                        // var iframe = window['layui-layer-iframe' + index];
                        //     iframe.child("auction");
                    }
                });
            } else if (obj.event === 'apply') {
                var WIDout_trade_no = data.bid;
                var WIDsubject = data.sname;//名称
                var WIDtotal_amount = data.preprice;//金额
                var WIDbody = '2';//2--商品支付，1--保证金
                var param = {};
                param.WIDout_trade_no = WIDout_trade_no;
                param.WIDtotal_amount = WIDtotal_amount;
                param.WIDsubject = WIDsubject;
                param.WIDbody = WIDbody;
                Base.gotoView("/paymentConfirmation", param)
            }
        });

    });

    function queryData() {
        var table = layui.table;
        var index = layer.msg("查询中，请等待...", {icon: 16, tiem: false, shade: 0});
        setTimeout(function () {
            table.reload('testTable', {
                page: {
                    curr: 1
                },
                where: {
                    sname: $("#sname").val(),
                    stype: $("#stype").val(),
                    aucstate: $("#aucstate").val(),
                    astatecode: $("#astatecode").val()
                }
            });
            layer.close(index);
        })
    }

    function closeWindow() {
        layer.close(static_index);
    }

    function getGoodsType() {
        $.ajax({
            type: "POST",
            contentType: "application/x-www-form-urlencoded; charset=utf-8", // post提交乱码
            url: "/goods/getStypeList.do",
            async: true,
            data: "",
            success: function (data) {
                if (data.success) {
                    $("#stype").html(html);
                    var html = "";
                    var list = data.list;
                    if (list != undefined && list.length > 0) {
                        html += "<option value=''>请选择</option>";
                        for (var i = 0; i < list.length; i++) {
                            html += "<option value='" + list[i].tid + "'>" + list[i].tname + "</option>";
                        }
                    } else {
                        html += "<option value=''>请选择</option>";
                    }
                    $("#stype").html(html);
                }
            }
        });
    }
</script>

</body>
</html>